package com.arknights.web.controller;

import com.arknights.web.domain.User;
import com.arknights.web.service.GetUsers;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/lservlet")
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("utf-8");
        String u_name = request.getParameter("u_name");
        String u_pwd = request.getParameter("u_pwd");
        System.out.println(u_pwd);
        System.out.println(u_name);
        GetUsers gu = new GetUsers();
        User user = gu.getUser(u_name);
        System.out.println(user);
        if (user != null) {
            if(user.getU_pwd().equals(u_pwd)) {
                response.getWriter().print("ok");
            }else {
                response.getWriter().print("用户名或密码错误");
            }
        } else{
            response.getWriter().print("用户名不存在");
        }
    }
}
